package com.paradogs.common.utils;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;

/**
 * @author: yumi
 * @date: 2025/3/29  14:59
 * @Description: TODO
 */
public class Virtual {
    public static void of(Runnable runnable) {
        try {
            CompletableFuture.runAsync(runnable).get();
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public static <T> T of(Supplier<T> supplier) {
        try {
            return CompletableFuture.supplyAsync(supplier).get();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
}
